/*
 * @Author: zhangweixin 
 * @Date: 2018-11-19 10:43:22 
 * @Last Modified by: zhangweixin
 * @Last Modified time: 2018-12-04 19:35:24
 */

import React,{Component} from 'react';
import { connect } from 'react-redux';
import {
  getUserInfo
} from '../../actions/userActions';

import Template from './template.jsx';

// import style from './style.less';
// import classNames from 'classnames/bind';
// const classMap = classNames.bind(style);

import NavTabBar from 'components/navTabBar/index.js'
class UserCenter extends Component{
  constructor(props){
    super(props);
    this.state={
      orderTypeFilters:[
        {label:"待付款", type: "waitpay"},
        { label: "待发货", type: "shipping"},
        { label: "配送中", type: "shipped"},
        { label: "交易成功", type: "success"},
      ],
      userNavItemsLinkArr:[
        {label:"店主收入查询",link:"/feedback",display:false},
        {label:"查看店主信息",link:"/feedback",display:false},
        {label:"意见反馈",link:"/feedback",display:true},
        // {label:"拨打电话",link:"/feedback",display:true}
      ]
    }
    this.render = Template;
    this.onGoToLoginHandler = this.onGoToLoginHandler.bind(this);
    this.onGoToOrderListHandler = this.onGoToOrderListHandler.bind(this);
    // this.onCallHandler = this.onCallHandler.bind(this);
  }
  componentWillMount(){
    document.title = "个人中心"
  }
  // render() {
  //   const {userInfo, isLoading, errorMsg} = this.props.userInfo;
  //   return (
  //     <div className={classMap("P-user-center")}>
  //       <div>111112</div>
  //       <NavTabBar />
  //     </div>
  //   )
  // }
  onGoToLoginHandler() {
    this.props.history.push("/login")
  }
  onCallHandler(){
    window.location.href = 'tel:' + 4000585825;
  }
  onGoToOrderListHandler(e){
    let orderType = e.currentTarget.getAttribute("data-ordertype")
    this.props.history.push(
      // 不使用对象传递，是因为怕用户在这个页面手动刷新，会拿不到值
      // {pathname:"/orderList",query:{type:orderType}}
      // {pathname:"/orderList",query:{type:orderType},state:{type:orderType}}
      "/orderList?type="+orderType
    )
  }
}

function mapStateToProps(state){
  return {
    userInfo:state.userInfo
  }
}

// const mapStateToProps = () =>{
//   return {
//     userInfo:state.userInfo
//   }
// }

function mapDispatchToProps(dispatch){
  return {
    getUserInfo:()=>{
      dispatch(getUserInfo())
    }
  }
}

export default connect(mapStateToProps,mapDispatchToProps)(UserCenter);